﻿<?php


class IconApp extends BaseApp
{

	var $phpscup_div = '';
	var $icon_to_array = array();
	

    function index()
    {

		$TB_icon = &$this->_model('icon'); 	 
		
		$data = $TB_icon->show();	
	    
		
        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']); 	
    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_list.view.php');
    }




    function edit()
    {	
		$id = intval($_GET['id']);
		$TB_icon = &$this->_model('icon');		
		$data = $TB_icon->oneshow($id);

		$this->icon_to_array($data['config']);
	    $data['config'] = $this->icon_to_array;

	    $tablearray = array();
	    $temparray = get_db()->tables();
		foreach($temparray as $key => $value)
		{
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;

			    }
			}

		}
        $temparray = & $GLOBALS['SCup']->_get_module_list_data();

		foreach($temparray as $key => $value)
		{
        $appnamearray [$value['id']] = $key;		
		}

        $cachearray = array();
        $cachearray['data/category/'] = get_all_dirname(ROOT_PATH . '/data/category');
        $cachearray['data/cache/'] = get_all_dirname(ROOT_PATH . '/data/cache');
        $cachearray['data/nav/'] = get_all_dirname(ROOT_PATH . '/data/nav');

        $htmlnamearray = array();
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon');
        $temparray1 = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icon.php');
		foreach($temparray1 as $key => $value)
		{

		   $htmlnamearray[$key] = $key.'.html';
		}

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $htmlnamearray[str_replace('.html','',$value)] = $value;
		   }
		}
        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}

        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('tablearray', $tablearray);
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));


	    $this->assign('data', $data);		
			

	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_edit.view.php');
    }

    function add()
    {	
	    $tablearray = $appnamearray= array();
	    $temparray = get_db()->tables();
		foreach($temparray as $key => $value)
		{
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;

			    }
			}

		}
        $temparray = & $GLOBALS['SCup']->_get_module_list_data();

		foreach($temparray as $key => $value)
		{
        $appnamearray [$value['id']] = $key;		
		}

        $cachearray = array();
        $cachearray['data/category/'] = get_all_dirname(ROOT_PATH . '/data/category');
        $cachearray['data/cache/'] = get_all_dirname(ROOT_PATH . '/data/cache');
        $cachearray['data/nav/'] = get_all_dirname(ROOT_PATH . '/data/nav');

        $htmlnamearray = array();
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon');
        $temparray1 = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icon.php');
		foreach($temparray1 as $key => $value)
		{

		   $htmlnamearray[$key] = $key.'.html';
		}

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $htmlnamearray[str_replace('.html','',$value)] = $value;
		   }
		}
        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}

        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('tablearray', $tablearray);
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_add.view.php');
    }


    function addpost()
    {

	     $data = $_POST['data'];


         $data['config'] = del_empty_var($data['config']);

		 if(empty($data['iconname'])&&empty($data['viewtype'])&&empty($data['description']))
		{
		 $notice = &get_message(array('msg'=>'String iconname,description or viewtype is NULL','url'=>'','title'=>'Notice'));
		 $notice ->display();
		 }

		if($data['get']['iconsettype']=='1')
		{
			   $icon_str =str_replace(array('<phpscup:icon','/>'),array('',''),$data['iconcontent']);
               $this->icon_to_array($icon_str);
			   $data['config'] = $this->icon_to_array;
               $data['config']['iconname'] = $data['iconname'];
 
		}
		else
		{		
           $data['config']['iconname'] = $data['iconname'];
          $data['iconcontent'] =$this->get_icon_str($data['config']);

		}

         unset($data['get']);
         $data['config']= $this->config_to_str($data['config']);

		 $TB_icon = &$this->_model('icon'); 	 
		
		 $TB_icon->post($data);
	
		 $this->index();

    }

    function editpost()
    {
		 $id = intval($_POST['id']);
	     $data = $_POST['data'];

         $data['config'] = del_empty_var($data['config']);

		 if(empty($data['iconname'])&&empty($data['viewtype'])&&empty($data['description']))
		{
		 $notice = &get_message(array('msg'=>'String iconname,description or viewtype is NULL','url'=>'','title'=>'Notice'));
		 $notice ->display();
		 }

		if($data['get']['iconsettype']=='1')
		{
			   $icon_str =str_replace(array('<phpscup:icon','/>'),array('',''),$data['iconcontent']);
               $this->icon_to_array($icon_str);
			   $data['config'] = $this->icon_to_array;
               $data['config']['iconname'] = $data['iconname'];
 
		}
		else
		{		
           $data['config']['iconname'] = $data['iconname'];
          $data['iconcontent'] =$this->get_icon_str($data['config']);

		}

         unset($data['get']);
         $data['config']= $this->config_to_str($data['config']);


		 $TB_icon = &$this->_model('icon'); 		 

		 $TB_icon->editaction($id,$data);
	 
		 $this->index();
		 

    }

    function viewmanageeditpost()
    {
		 $pagename = $_POST['pagename'];
		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];
		 		 	
		 $strdata = $this->filtrate($strtempdata);	 
	     $data = $_POST['data'];

         $data['config'] = del_empty_var($data['config']);

		 if(empty($data['iconname']))
		{
		 $notice = &get_message(array('msg'=>'String iconname is NULL','url'=>'','title'=>'Notice'));
		 $notice ->display();
		 }

		if($data['get']['iconsettype']=='1')
		{
			   $icon_str =str_replace(array('<phpscup:icon','/>'),array('',''),$data['iconcontent']);
               $this->icon_to_array($icon_str);
			   $data['config'] = $this->icon_to_array;
               $data['config']['iconname'] = $data['iconname'];			   
		}
		else
		{	$data['iconcontent']='';	
             $data['config']['iconname'] = $data['iconname'];
		     foreach($data['config'] as $key => $value)
		     {
			 $data['iconcontent'] .= '  '.$key."=\'".$value."\'";
		     }			 	  	
		}
               $data['iconcontent'] = str_replace(array('<phpscup:icon','/>'),array('',''),$data['iconcontent']);		
		       $data['iconcontent'] = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$data['iconcontent']);			

		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';

		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}
		
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $data['iconcontent'], $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename, $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	
    }

	function _urldecode($msg){
		$msg = urldecode($msg);		
		$msg = str_replace(';gang;','-',$msg);
	
		return $msg;
	}
	function _urlencode($msg){
		$msg = str_replace('-',';gang;',$msg);
		$msg = urlencode($msg);		
		return $msg;
	}

    function viewmanageedit()
    {	
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];
		
		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
	    $data['config'] = $this->icon_to_array;
		$data['iconcontent'] = '<phpscup:icon '.$strdata.' />';
		$data['iconname'] = $iconname;	
			
	    $tablearray = array();
	    $temparray = get_db()->tables();
		foreach($temparray as $key => $value)
		{
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;

			    }
			}

		}
        $temparray = & $GLOBALS['SCup']->_get_module_list_data();

		foreach($temparray as $key => $value)
		{
        $appnamearray [$value['id']] = $key;		
		}

        $cachearray = array();
        $cachearray['data/category/'] = get_all_dirname(ROOT_PATH . '/data/category');
        $cachearray['data/cache/'] = get_all_dirname(ROOT_PATH . '/data/cache');
        $cachearray['data/nav/'] = get_all_dirname(ROOT_PATH . '/data/nav');

        $htmlnamearray = array();
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon');
        $temparray1 = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icon.php');
		foreach($temparray1 as $key => $value)
		{

		   $htmlnamearray[$key] = $key.'.html';
		}

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $htmlnamearray[str_replace('.html','',$value)] = $value;
		   }
		}
        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}

        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('tablearray', $tablearray);
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));


	    $this->assign('data', $data);
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
							
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_viewmanageedit.view.php');
    }

	function filtrate($msg){
		$msg = str_replace(';deng;','=',$msg);
		$msg = str_replace(';kong;',' ',$msg);
		$msg = str_replace(';shuang;','"',$msg);
		$msg = str_replace(';dang;',"'",$msg);
		$msg = str_replace(';and;',"&&",$msg);		
		$msg = str_replace(';or;',"||",$msg);
		$msg = str_replace(';gang;',"-",$msg);				
		return $msg;
	}

    function viewmanagedataedit()
    {	
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
	   if($action=='post')
	   {
		 $pagename = $_POST['pagename'];		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];	   
	     $fids = $_POST['fids'];		 
	     $tplpath = $_POST['tplpath'];		 
	     $tplpart_1 = $_POST['tplpart_1'];		 
	     $data = $_POST['data'];		 
	     $fenorxin = $_POST['fenorxin'];
	     $mokuai = $_POST['mokuai'];
	     $limitnum = $_POST['limitnum'];
		 if(empty($limitnum))
		 {
		 $limitnum = 10;
		 }
		 
		 $strdata = $this->filtrate($strtempdata);	 
         $this->icon_to_array($strdata);
	     $old_icondata = $this->icon_to_array;

		 $fields_str = '';
		 if(isset($data)&&!empty($data))
		 {
		   foreach($data as $key => $value)
		   {
		     $fields_str .= $value['datavalue'].':'.$value['datakey'].'|'; 
		   }
		 }
		 $old_icondata['htmlname'] = str_replace('.html','',basename($tplpath));
		 $old_icondata['fields'] = $fields_str;
		 $old_icondata['limit']='0,'.$limitnum;			 	
         if($mokuai==1)
		 {
  		    $temp_html_name = del_empty_var(explode(".",$old_icondata['htmlname']));
		    $old_icondata['htmlname'] = $temp_html_name[0];			
		    $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		    $icon_dir = ROOT_PATH . $dir;
		    $iconfile = $old_icondata['htmlname'].'.'.time().'.html';
		    $iconfilename = $old_icondata['htmlname'].'.'.time().'';
		    $old_icondata['htmlname'] = $iconfilename;			
	        $temparray = get_all_dirname($icon_dir);
            $is = 1;
	        foreach($temparray as $key => $value)
		    {
		      if($value==$iconfile)
		      {
              $is = 0;break;
		      }	
            }
			
		    if($is)
		    {
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }		
		    }
		    else
		    {		
		      $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新提交','url'=>'','title'=>'Notice'));
		      $notice ->display();			
		    }
		     
		 }else if ($mokuai==0)
		 {

		        $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		        $icon_dir = ROOT_PATH . $dir;
		        $iconfile = $old_icondata['htmlname'].'.html';
		        $iconfilename = $old_icondata['htmlname'];		 
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			 
		 }
		 $temp_table_catid = array();
         if(isset($fids[0]))
		 {
		     foreach($fids as $key=>$value)
			 {
  		       $temp_fids_array = del_empty_var(explode("_",$value));
			   if(!isset($temp_fids_array[0]))$temp_fids_array[0]='';
			   if(!isset($temp_fids_array[1]))$temp_fids_array[1]='';			   
			   if(!isset($temp_fids_array[2]))$temp_fids_array[2]='';			   
			   $temp_table_catid[$key]['tableid'] = $temp_fids_array[0];
			   $temp_table_catid[$key]['catid'] = $temp_fids_array[1];			   
			   $temp_table_catid[$key]['id'] = $temp_fids_array[2];			   			   			    
			 }	
		     $old_icondata['tablename'] = 'content_'.$temp_table_catid[0]['tableid'];
            $temparray = & $GLOBALS['SCup']->_get_module_list_data();
		    foreach($temparray as $key => $value)
		    {
		      if($value['id']==$temp_table_catid[0]['tableid'])
		      {
		       $appname = $value['appname'];
		      }				
		    }			 
		 
		    if($fenorxin=='1')
		    {
			    $conditions = ' is_show=1 and (';
				foreach($temp_table_catid as $key => $value)
				{
				   $conditions .= ' cat_id='.$value['catid'].' or ';
				}
				$conditions = substr($conditions,0,-3);	
				$conditions = $conditions.')';					
			    $old_icondata['conditions']=$conditions;
			    $old_icondata['order']='content_'.$temp_table_catid[0]['tableid'].'.add_time desc';				
			    $old_icondata['limit']='0,'.$limitnum;	
			    $old_icondata['pageurl']='?app='.$appname.'&act=index&cat=$GLOBALS[cat]';														
		    }
		    else
		    {	
			    $conditions = ' is_show=1 and (';
				foreach($temp_table_catid as $key => $value)
				{
				   $conditions .= ' id='.$value['id'].' or ';
				}
				$conditions = substr($conditions,0,-3);	
				$conditions = $conditions.')';					
			    $old_icondata['conditions']=$conditions;
			    $old_icondata['order']='content_'.$temp_table_catid[0]['tableid'].'.add_time desc';				
			    $old_icondata['limit']='0,'.$limitnum;				
			 			
			}			 				 	 
		 }

		foreach($old_icondata as $key => $value)
		{
		   $iconcontent .= '  '.$key."=\'".$value."\'";
		}			 	  	

		$iconcontent = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$iconcontent);			

		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';
		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}		
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $iconcontent, $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename,  $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	
   
	   }
       if($action=="getTplcode")
	   {
	   $divid = $_GET['divid'];	
	   $filepath = $_GET['filepath'];
	   $filepath=str_replace(SITE_URL,"",$filepath);	

		$code= str_replace(array("\r","\n"),array('\r','\n'), read_file(ROOT_PATH.$filepath));	 
    	echo "<SCRIPT LANGUAGE=\"JavaScript\">
	    <!--
	    parent.puthtmlcode('$code');
	    //-->
	    </SCRIPT>";
	    exit;
       }	   
	   			 	   
       if($action=='getfidsonslist')
	   { 
	      $fup = $_GET['fup'];
		  $class = $_GET['class'];
		  $ctype = $_GET['ctype'];
		  $page =  $_GET['page'];
		  $Murl = SITE_URL.'/admin/'; 
	      $temparray = get_db()->tables();
		  foreach($temparray as $key => $value)
		  {
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;

			    }
			 }
		  }
	  
          header('Content-type: text/html; charset='.VIEW_CHARSET);
		  
  		 $table_catid = del_empty_var(explode("_",$fup));
		 if(!isset($table_catid[1]))
		 {
		 $table_catid[1]='';
		 }	 	
		 $TB_icon = &$this->_model('icon');		
		 $data = $TB_icon->categoryshow('',$table_catid[0],$table_catid[1]);
		 $select_str = "";		 
		 foreach($tablearray[DB_PREFIX.'content_'.$table_catid[0]] as $key => $value)
		 {              
          $select_str .= '<option  value="'.$value.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key.'</option>';	   
		 }
		 
         $str='';
		  foreach($data['data'] as $key => $value)
		  {
		        $next='false';
		        $icon_fup = true;
				$str.= "<div><a href=\"javascript:;\" onclick=\"changeClassName($class,this,\'".$table_catid[0].'_'.$value['cat_id'].'_'.$value['id']."\',$next,$ctype ,\'$Murl\')\">".'['.$value['id'].']'.$value['description']."</a></div>"; 	
			   
		  }			  
	     $str=$str?$str:"&nbsp;";
	     echo '<script >parent.inputcontent(\''.$str.'\','.$class.',\''.$select_str.'\');</script>';
	     exit;	
       }		
	
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];

		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
	    $data['config'] = $this->icon_to_array;
		
        $iconfield =  del_empty_var(explode("|",$data['config']['fields']));
		$iconfielddata = array();
        foreach($iconfield as $key => $value)
		{
		   $temp = del_empty_var(explode(":",$value));
		   $iconfielddata[$temp[1]] = $temp[0];
		}
        $limitnum = del_empty_var(explode(",",$data['config']['limit']));

		if(empty($limitnum[1]))$limitnum[1]=10;
	    $limitnum = $limitnum[1];
	   
		$data['iconcontent'] = '<phpscup:icon '.$strdata.' />';
		$data['iconname'] = $iconname;	
			
	    $tablearray = array();
	    $temparray = get_db()->tables();
		foreach($temparray as $key => $value)
		{
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;
			    }
			}

		}
        $temparray = & $GLOBALS['SCup']->_get_module_list_data();
        $categorydata = array();
		foreach($temparray as $key => $value)
		{
        $appnamearray[$value['id']] = $key;
		$categorydata[$value['id']]['alias']=$value['alias'];
		$categorydata[$value['id']]['appname']=$value['appname'];
		$categorydata[$value['id']]['category']=@include(ROOT_PATH . '/data/category/category_'. $key .'.php');					
		}

        $cachearray = array();
        $cachearray['data/category/'] = get_all_dirname(ROOT_PATH . '/data/category');
        $cachearray['data/cache/'] = get_all_dirname(ROOT_PATH . '/data/cache');
        $cachearray['data/nav/'] = get_all_dirname(ROOT_PATH . '/data/nav');

        $htmlnamearray = array();
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon');
        $temparray1 = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icon.php');
		foreach($temparray1 as $key => $value)
		{

		   $htmlnamearray[$key] = $key.'.html';
		}

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $htmlnamearray[str_replace('.html','',$value)] = $value;
		   }
		}
        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}


		$code= read_file(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/'.$data['config']['htmlname'].'.html');	 

        $icontabledata = '';
        if(isset($data['config']['tablename'])&&!empty($data['config']['tablename'])&&!strstr($data['config']['tablename'],'|'))
		{	
		    $sql_order ='';
		    $sql_limit = '';
		    $sql_conditions = '';
		    $sql_table = '';
		    $sql_field = 'id,cat_id,description';
			$tableid = '';
			$sql = '';			
            if(isset($data['config']['order']))
		    {
		      $sql_order = ''.$data['config']['order'];		
		    }
            if(isset($data['config']['limit']))
		    {
		      $sql_limit = ''.$data['config']['limit'];		
		    }
            if(isset($data['config']['conditions']))
		    {
		      $sql_conditions = ''.$data['config']['conditions'];		
		    }
			$temp =  del_empty_var(explode("_",$data['config']['tablename']));
			$tableid = $temp[1];									
		    $sql_table = DB_PREFIX.$data['config']['tablename'].' '.$data['config']['tablename'];
			$tempcategorydata =  $categorydata[$tableid]['category'];
			
			$tempcategorydata1 = array();
			foreach($tempcategorydata as $key => $value)
			{
			    $tempcategorydata1[$value['cat_id']] = $value['cat_name'];
			}
		    $TB_icon = &$this->_model('icon');		
		    $tempdata = $TB_icon->iconshow($sql_table,$sql_field,$sql_conditions, $sql_order,$sql_limit);
			foreach($tempdata as $key => $value)
			{
			    $icontabledata .= '<div id="div_'.$tableid.'_'.$value['cat_id'].'_'.$value['id'].'"><input type="checkbox" name="fids[]" value="'.$tableid.'_'.$value['cat_id'].'_'.$value['id'].'" checked="" onclick="removeFid(this);">  <font color="#232323"> &gt; '.$categorydata[$tableid]['alias'].' &gt; '.$tempcategorydata1[$value['cat_id']].' &gt; ['.$value['id'].']'.$value['description'].'</font></div>';			
			}
       
		}
		$is_fenorxin = 1;
		if(isset($data['config']['conditions'])&&!empty($data['config']['conditions'])&&!strstr($data['config']['conditions'],'cat_id=')&&strstr($data['config']['conditions'],'id='))
		{
			$is_fenorxin = 0;
		}
		
        $this->assign('is_fenorxin', $is_fenorxin);		
        $this->assign('icontabledata', $icontabledata);
	
        $this->assign('code', $code);
        $this->assign('htmlname', $data['config']['htmlname']);		

        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('tablearray', $tablearray);
        $this->assign('tablename', DB_PREFIX.$data['config']['tablename']);
		     
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));
	    $this->assign('categorydata', $categorydata);
	    $this->assign('iconfielddata', $iconfielddata);
	    $this->assign('limitnum', $limitnum);
		
	    $this->assign('data', $data);
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
						
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_viewmanagedataedit.view.php');
    }






    function viewmanagehtmledit()
    {	
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
	   if($action=='post')
	   {
		 $pagename = $_POST['pagename'];		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];	   
	 
	     $tplpart_1 = $_POST['tplpart_1'];		 

	     $mokuai = $_POST['mokuai'];
	     $filename = $_POST['filename'];

		 
		 $strdata = $this->filtrate($strtempdata);	 
         $this->icon_to_array($strdata);
	     $old_icondata = $this->icon_to_array;


		 	
         if($mokuai==1)
		 {
  		    $temp_html_name = del_empty_var(explode(".",$old_icondata['htmlname']));
		    $old_icondata['htmlname'] = $temp_html_name[0];			
		    $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		    $icon_dir = ROOT_PATH . $dir;
			if($filename)
			{
		    $iconfile = $filename.'.html';
		    $iconfilename = $filename.'';
		    $old_icondata['htmlname'] = $iconfilename;					
			}else
			{
		    $iconfile = $old_icondata['htmlname'].'.'.time().'.html';
		    $iconfilename = $old_icondata['htmlname'].'.'.time().'';
		    $old_icondata['htmlname'] = $iconfilename;					
			}
		
	        $temparray = get_all_dirname($icon_dir);
            $is = 1;
	        foreach($temparray as $key => $value)
		    {
		      if($value==$iconfile)
		      {
              $is = 0;break;
		      }	
            }
			
		    if($is)
		    {
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }		
		    }
		    else
		    {		
		      $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新提交','url'=>'','title'=>'Notice'));
		      $notice ->display();			
		    }
		     
		 }else if ($mokuai==0)
		 {

		        $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		        $icon_dir = ROOT_PATH . $dir;
		        $iconfile = $old_icondata['htmlname'].'.html';
		        $iconfilename = $old_icondata['htmlname'];		 
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			 
		 }


		foreach($old_icondata as $key => $value)
		{
		   $iconcontent .= '  '.$key."=\'".$value."\'";
		}			 	  	

		$iconcontent = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$iconcontent);			

		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';
		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}		
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $iconcontent, $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename,  $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	
   
	   }

	
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];

		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
	    $data['config'] = $this->icon_to_array;
		
        $iconfield =  del_empty_var(explode("|",$data['config']['fields']));
		$iconfielddata = array();
        foreach($iconfield as $key => $value)
		{
		   $temp = del_empty_var(explode(":",$value));
		   $iconfielddata[$temp[1]] = $temp[0];
		}
        $limitnum = del_empty_var(explode(",",$data['config']['limit']));

		if(empty($limitnum[1]))$limitnum[1]=10;
	    $limitnum = $limitnum[1];
	   
		$data['iconcontent'] = '<phpscup:icon '.$strdata.' />';
		$data['iconname'] = $iconname;	
			


		$code= read_file(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/'.$data['config']['htmlname'].'.html');	 

	
        $this->assign('code', $code);
        $this->assign('htmlname', $data['config']['htmlname']);		


		
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
						
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_viewmanagehtmledit.view.php');
    }




    function viewmanagetableuseredit()
    {	
	   $changeClassName = array(
	     array('name' =>'用户表',
		       'table' =>'users',
			   'filed1' =>'users.user_id',
			   'filed2' =>'users.user_name',			   
	          ),
	     array('name' =>'|--消费记录表',
		       'table' =>'users.user_id|usermoney.userid',
			   'filed1' =>'usermoney.mid',
			   'filed2' =>'usermoney.intro',			   
	          ),			  
	   );
	
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
 	    if($action=='post')
	    {
		
		    $pagename = $this->_urldecode($_POST['pagename']);		 
		    $strtempdata = $_POST['strtempdata'];		 
		    $fromurl = $this->_urldecode($_POST['fromurl']); 

		    $filedlist = trim($_POST['filedlist']);			
			
	        $fids = $_POST['fids'];
		 		 
	        $data = $_POST['data'];
            unset($data['dopost']);			
	        $fenorxin = $_POST['fenorxin'];
	        $limitnum = $_POST['limitnum'];
			
		    if(empty($limitnum)) {
		        $limitnum = 10;
		    }
		 		 
		    $strdata = $this->filtrate($strtempdata);	 
            $this->icon_to_array($strdata);
	        $old_icondata = $this->icon_to_array;


		    $old_icondata['fields'] = $filedlist;
		    $old_icondata['limit']='0,'.$limitnum;			 	

		    $temp_table_filed_id = array();
            if(isset($fids[0])) {

  		        $temp_fids_array = del_empty_var(explode(",",$fids[0]));
			    if(!isset($temp_fids_array[0]))$temp_fids_array[0]='';
			    if(!isset($temp_fids_array[1]))$temp_fids_array[1]='';			   
			    $temp_table_filed_id['tablename'] = $temp_fids_array[0];
			    $temp_table_filed_id['filedname'] = $temp_fids_array[1];
		        foreach($fids as $key=>$value) {
  		            $temp_fids_array = del_empty_var(explode(",",$value));			   
			        if(!isset($temp_fids_array[2]))$temp_fids_array[2]='';	   
			        $temp_table_filed_id['id'][$key] = $temp_fids_array[2];			   			   			    
			    }			    
	
		        $old_icondata['tablename'] = $temp_table_filed_id['tablename'];
	 
		        if($fenorxin=='1') {
				    $conditions = '';					
			        $old_icondata['conditions']=$conditions;
			        $old_icondata['order']='';				
			        $old_icondata['limit']='0,'.$limitnum;	
			        $old_icondata['pageurl']='';
																		
		        } else {	
			        $conditions = '(';
				    foreach($temp_table_filed_id['id'] as $key => $value) {
				        $conditions .= ' '.$temp_table_filed_id['filedname'].'='.$value.' or ';
				    }
				    $conditions = substr($conditions,0,-3);	
				    $conditions = $conditions.')';					
			        $old_icondata['conditions']=$conditions;
			        $old_icondata['order']='';				
			        $old_icondata['limit']='0,'.$limitnum;				
			 			
			    }			 				 	 
		    }
            $iconcontent = '';
		    foreach($old_icondata as $key => $value) {
		        $iconcontent .= '  '.$key."=\'".$value."\'";
		    }			 	  	
      
		    $iconcontent = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$iconcontent);			


		    $filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		    $savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		    $savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';			
			
		    $tempfilename = '';				
		    if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		    {			
		        $tempfilename = $savefilename;				   			
		    } else {
		        $tempfilename = $filename;					
		    }		
		    $fileContent = "";
		    if (!($fileContent = file_get_contents($tempfilename))) {
				return false;
		    }
				
		    $fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		    $fileContent = str_replace($strdata, $iconcontent, $fileContent);
		
		    if (!file_exists($savefilename)) {
				get_dir($savedir);
		    }
		
		    if (!file_put_contents($savefilename,  $fileContent)) {
			    return false;
		    }
 		    $notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		    $notice ->display();	
   
	    } 
		   
	   			 	   
        if($action=='getfidsonslist')
	    { 
	      $fup = $_GET['fup'];
		  $class = $_GET['class'];
		  $ctype = $_GET['ctype'];
		  $page =  $_GET['page'];
		  $Murl = SITE_URL.'/admin/'; 

	      $temparray = get_db()->tables();
		  foreach($temparray as $key => $value)
		  {
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;

			    }
			 }
		  }		
			  
            header('Content-type: text/html; charset='.VIEW_CHARSET);	
		  
  		    $tables_fileds = del_empty_var(explode(",",$fup));

		    $tablename_array = array();
		    $fields_array = array();
		    $temp_fields_array = array();
		    $temp_fields_array1 = array();		 		 
            $data = array();
		 	 
            if(isset($tables_fileds[0])&&!empty($tables_fileds[0]))
		    {
		        $temp = $temp1 = array();	
		        $temp = explode("|",$tables_fileds[0]);			
                $temp = del_empty_var($temp);
			    $num=1;
                foreach($temp as $key => $value)
			    {
		            $temp1 = explode(".",$value);
				    if(isset($temp1[1]))
				    {
				        $tablename_array[$num]['table'] = $temp1[0];
				        $tablename_array[$num]['field'] = $temp1[1];
				    } else {
				        $tablename_array[$num]['table'] = $temp1[0];
				        $tablename_array[$num]['field'] = 0;			
				    }
				    $num++;
			    }

		    }
	
            if(isset($tables_fileds[1])&&!empty($tables_fileds[1]))
		    {
		        $temp = $temp1 = array();	
		        $temp = explode("|",$tables_fileds[1]);			
                $temp = del_empty_var($temp);
			
                foreach($temp as $key => $value)
			    {
		            $temp1 = explode(":",$value);
				    if(isset($temp1[1]))
				    {
				        $fields_array[$temp1[0]] = $temp1[1];
				    }else{
				        $fields_array[$temp1[0]] = 0;				
				    }
				    $temp3 = explode(".",$temp1[0]);
                    $temp_fields_array1[$key] = $temp1[0];								
                    $temp_fields_array[$key] = $temp3[1];				
			    }
		    }



		    if(isset($tables_fileds[0])&&isset($tables_fileds[1])&&!empty($tables_fileds[0])&&!empty($tables_fileds[1])){     
			    $temp_on = '';
			    $table_pre_key = '';
			    $table_pre_value = '';

                if(count($tablename_array)==1)
			    {
			        $tables = DB_PREFIX.$tablename_array[1]['table']. ' '.$tablename_array[1]['table'];
			    } else {
                    for($num=1;$num<=count($tablename_array);$num++)
		            {
				        if(empty($tablename_array[$num]['field'])){$tablename_array[$num]['field'] = ' ';}

                        if(isset($tablename_array[$num+1])&&$num==1) {	

                            $tables.= DB_PREFIX.$tablename_array[$num]['table'] . ' '.$tablename_array[$num]['table'].' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';
				  
				        } else {   
					        if(isset($tablename_array[$num+1]))
					        {
	                          $tables.= ' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';						  
					        }
		  
				        }
		            }	
			    }

                foreach($fields_array as $key => $value)
		        {
			        if(empty($value))
			        {
                        $fields.= $key . ' ,';			
			        }else {
                        $fields.= $key . ' as '.$value.' ,';			
			        }
		        }
  			    $fields = substr($fields, 0,-1);

			  $data =  get_model()->Page_And_S_Sql_Exe(array("table" => $tables,"fields" => $fields,"conditions" => '',"order" => '',"limit" => '20',"return" => "all","url" =>''));
		    }

           
		    $select_str = "";

		    foreach($tablename_array as $key => $value)
		    {
		    
		        foreach($tablearray[DB_PREFIX.$value['table']] as $key1 => $value1)
		        {			             
                    $select_str .= '<option  value="'.$value1.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key1.'</option>';	   
		        }
			    $select_str .= '<optgroup label="===================" style="color:red;"></optgroup>';	 

		    }
		 		 

		 
            $str='';
		    foreach($data['data'] as $key => $value)
		    {
		        $next='false';
		        $icon_fup = true;
				if($value[$temp_fields_array[0]])
				{
				$str.= "<div><a href=\"javascript:;\" onclick=\"changeClassName($class,this,\'".$tables_fileds[0].','.$temp_fields_array1[0].','.$value[$temp_fields_array[0]]."\',$next,$ctype ,\'$Murl\')\">".'['.$value[$temp_fields_array[0]].']'.$value[$temp_fields_array[1]]."</a></div>"; 				
				}
	
			   
		    }			  
	        $str=$str?$str:"&nbsp;";
	        echo '<script >parent.inputcontent(\''.$str.'\','.$class.',\''.$select_str.'\');</script>';
	        exit;	
        }
  
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];

		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];	
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		

  		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
	    $data['config'] = $this->icon_to_array;

		
		
		if(!isset($data['config']['limit'])){
		    $data['config']['limit'] = '';
		}
		
        $limitnum = del_empty_var(explode(",",$data['config']['limit']));

		if(empty($limitnum[1]))$limitnum[1]=10;
	    $limitnum = $limitnum[1];
		
   
		$data['iconcontent'] = '<phpscup:icon '.$strdata.' />';
		$data['iconname'] = $iconname;	

	    $tablearray = array();
	    $temparray = get_db()->tables();
		foreach($temparray as $key => $value)
		{
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;
			    }
			}

		}

/* <phpscup:filedlist>
 post = post.title:icon1|post.content:icon2|post.id:icon4| ;
 post1 = post1.title:icon1|post1.content:icon2|post1.id:icon3|;
</phpscup:filedlist>*/	

		$code= read_file(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/'.$data['config']['htmlname'].'.html');	 
		
		preg_replace("/\<phpscup\:filedlist\>\s*(.+?)\s*\<\/phpscup\:filedlist\>/ies", "\$this->_filed_list_code('\\1')", $code);
        if(is_array($this->_filedlistcode) && !empty($this->_filedlistcode) && isset($this->_filedlistcode[$data['config']['tablename']])) {
		    $data['config']['fields'] = $this->_filedlistcode[$data['config']['tablename']];
			$isdo = 1 ;
			foreach($changeClassName as $key => $value) {
			    if($value['table'] == $data['config']['tablename'] ) {
                    $changeClassName = array($value) ;
					$isdo = 0 ;
					break;
                }				
			}
            if($isdo) {
	            $changeClassName = array(
	                array('name' =>'表名为'.$data['config']['tablename'].'的数据',
		                'table' =>$data['config']['tablename'],
			            'filed1' =>$data['config']['tablename'].'.id',
			            'filed2' =>$data['config']['tablename'].'.id',			   
	                ),			  
	            );
            }
	        $changeClassName[] = 
	            array('name' =>'退回数据',
		                'table' =>'',
			            'filed1' =>'',
			            'filed2' =>'',			   
	            );			  			
		}
 	
        $icontabledata = '';
        if(isset($data['config']['tablename'])&&!empty($data['config']['tablename']))
		{	
		
		    $sql_order ='';
		    $sql_limit = '';
		    $sql_conditions = '';
		    $sql_table = '';
		    $sql_field = '';
			$tableid = '';
			$sql = '';
			
		    $tempclass_name = array();					
		    $tablename_array = array();
		    $fields_array = array();
		    $fields_temp_array = array();								
		    $temp = $temp1 = array();	
		    $temp = explode("|",$data['config']['tablename']);			
            $temp = del_empty_var($temp);
			$num=1;
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(".",$value);
				if(isset($temp1[1]))
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = $temp1[1];
				}
				else
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = 0;			
				}
				$num++;
			}
            foreach($changeClassName as $key => $value )
			{
  		       if($value['table']==$data['config']['tablename'])
			   {
			     $categorydata =  $value['name'];
				 $tempclass_name = $value;
			     $fields_array[$value['filed1']] = 0;
			     $fields_array[$value['filed2']] = 0;
				 $temp = explode(".",$value['filed1']);
				 $fields_temp_array[1]= $temp[1];
				 $temp = explode(".",$value['filed2']);
				 $fields_temp_array[2]= $temp[1];				 				 			   
			   }
			}
			
            if(count($tablename_array)==1)
			{
			   $sql_table = DB_PREFIX.$tablename_array[1]['table']. ' '.$tablename_array[1]['table'];
			}
			 else
			{
              for($num=1;$num<=count($tablename_array);$num++)
		      {
				  if(empty($tablename_array[$num]['field'])){$tablename_array[$num]['field'] = ' ';}

                  if(isset($tablename_array[$num+1])&&$num==1)
				  {	

                  $sql_table.= DB_PREFIX.$tablename_array[$num]['table'] . ' '.$tablename_array[$num]['table'].' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';
				  
				  }
				  else
				  {   
					  if(isset($tablename_array[$num+1]))
					  {
	                  $sql_table.= ' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';						  
					  }
		  
				  }


		      }	
			  
			}

            foreach($fields_array as $key => $value)
		    {
			   if(empty($value))
			   {
                $sql_field.= $key . ' ,';			
			   }else
			   {
                $sql_field.= $key . ' as '.$value.' ,';			
			   }
		    }
  			$sql_field = substr($sql_field, 0,-1);
		
			
            if(isset($data['config']['order']))
		    {
		      $sql_order = ''.$data['config']['order'];		
		    }
            if(isset($data['config']['limit']))
		    {
		      $sql_limit = ''.$data['config']['limit'];		
		    }
            if(isset($data['config']['conditions']))
		    {
		      $sql_conditions = ''.$data['config']['conditions'];		
		    }

		    $TB_icon = &$this->_model('icon');		
		    $tempdata = $TB_icon->iconshow($sql_table,$sql_field,$sql_conditions, $sql_order,$sql_limit);
		
			
			foreach($tempdata as $key => $value)
			{
			    if(isset($value[$fields_temp_array[1]])&&!empty($value[$fields_temp_array[1]]))
				{
			    $icontabledata .= '<div id="div_'.$tempclass_name['table'].'_'.$tempclass_name['filed1'].'_'.$value[$fields_temp_array[1]].'"><input type="checkbox" name="fids[]" value="'.$tempclass_name['table'].','.$tempclass_name['filed1'].','.$value[$fields_temp_array[1]].'" checked="" onclick="removeFid(this);">  <font color="#232323"> &gt; '.$categorydata.' &gt; ['.$value[$fields_temp_array[1]].']'.$value[$fields_temp_array[2]].'</font></div>';				
				}else
				{
				$icontabledata .= '';
				}
			
			}
       
		}
		$is_fenorxin = 1;
		if(isset($data['config']['conditions'])&&!empty($data['config']['conditions'])&&!strstr($data['config']['conditions'],'cat_id=')&&strstr($data['config']['conditions'],'id='))
		{
			$is_fenorxin = 0;
		}

        $this->assign('is_fenorxin', $is_fenorxin);		
        $this->assign('icontabledata', $icontabledata);
	
        $this->assign('code', $code);
        $this->assign('htmlname', $data['config']['htmlname']);
				
        $this->assign('changeClassName', $changeClassName);
		
        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('tablearray', $tablearray);
        $this->assign('tablename_array', $tablename_array);
				
        $this->assign('tablename', DB_PREFIX.$data['config']['tablename']);
		     
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));
	    $this->assign('categorydata', $categorydata);
	    $this->assign('iconfielddata', $iconfielddata);
	    $this->assign('limitnum', $limitnum);
		
	    $this->assign('data', $data);
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
						
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_viewmanagetableuseredit.view.php');

    }	


	function _filed_list_code($str = '')
	{
		$str= str_replace(array("\r","\n"),array('',''),$str );
		$temp = del_empty_var(explode(";",$str));
		$temp1 = array();
        foreach($temp as $key => $value) {
            $temp2 = del_empty_var(explode("=",$value)) ;
			$temp1[trim($temp2[0])] = trim($temp2[1]);			
        }		
	    $this->_filedlistcode = $temp1 ;
	}		
	


    function viewmanagetableedit()
    {	
	   $changeClassName = array(
	     array('name' =>'用户表',
		       'table' =>'users',
			   'filed1' =>'users.user_id',
			   'filed2' =>'users.user_name',			   
	          ),
	     array('name' =>'|--消费记录表',
		       'table' =>'users.user_id|usermoney.userid',
			   'filed1' =>'usermoney.mid',
			   'filed2' =>'usermoney.intro',			   
	          ),			  
	   );
	
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
	   if($action=='post')
	   {
		 $pagename = $_POST['pagename'];		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];	   
	     $fids = $_POST['fids'];
		 
	     $tplpath = $_POST['tplpath'];		 
	     $tplpart_1 = $_POST['tplpart_1'];		 
	     $data = $_POST['data'];		 
	     $fenorxin = $_POST['fenorxin'];
	     $mokuai = $_POST['mokuai'];
	     $limitnum = $_POST['limitnum'];
		 if(empty($limitnum))
		 {
		 $limitnum = 10;
		 }
		 		 
		 $strdata = $this->filtrate($strtempdata);	 
         $this->icon_to_array($strdata);
	     $old_icondata = $this->icon_to_array;

		 $fields_str = '';
		 if(isset($data)&&!empty($data))
		 {
		   foreach($data as $key => $value)
		   {
		     $fields_str .= $value['datavalue'].':'.$value['datakey'].'|'; 
		   }
		 }
		 $old_icondata['htmlname'] = str_replace('.html','',basename($tplpath));
		 $old_icondata['fields'] = $fields_str;
		 $old_icondata['limit']='0,'.$limitnum;			 	
         if($mokuai==1)
		 {
  		    $temp_html_name = del_empty_var(explode(".",$old_icondata['htmlname']));
		    $old_icondata['htmlname'] = $temp_html_name[0];			
		    $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		    $icon_dir = ROOT_PATH . $dir;
		    $iconfile = $old_icondata['htmlname'].'.'.time().'.html';
		    $iconfilename = $old_icondata['htmlname'].'.'.time().'';
		    $old_icondata['htmlname'] = $iconfilename;			
	        $temparray = get_all_dirname($icon_dir);
            $is = 1;
	        foreach($temparray as $key => $value)
		    {
		      if($value==$iconfile)
		      {
              $is = 0;break;
		      }	
            }
			
		    if($is)
		    {
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }		
		    }
		    else
		    {		
		      $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新提交','url'=>'','title'=>'Notice'));
		      $notice ->display();			
		    }
		     
		 }else if ($mokuai==0)
		 {

		        $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		        $icon_dir = ROOT_PATH . $dir;
		        $iconfile = $old_icondata['htmlname'].'.html';
		        $iconfilename = $old_icondata['htmlname'];		 
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			 
		 }
		 $temp_table_filed_id = array();
         if(isset($fids[0]))
		 {

  		     $temp_fids_array = del_empty_var(explode(",",$fids[0]));
			 if(!isset($temp_fids_array[0]))$temp_fids_array[0]='';
			 if(!isset($temp_fids_array[1]))$temp_fids_array[1]='';			   
			 $temp_table_filed_id['tablename'] = $temp_fids_array[0];
			 $temp_table_filed_id['filedname'] = $temp_fids_array[1];
		     foreach($fids as $key=>$value)
			 {
  		       $temp_fids_array = del_empty_var(explode(",",$value));			   
			   if(!isset($temp_fids_array[2]))$temp_fids_array[2]='';	   
			   $temp_table_filed_id['id'][$key] = $temp_fids_array[2];			   			   			    
			 }				   			   			    
	
		     $old_icondata['tablename'] = $temp_table_filed_id['tablename'];
	 
		    if($fenorxin=='1')
		    {
				$conditions = '';					
			    $old_icondata['conditions']=$conditions;
			    $old_icondata['order']='';				
			    $old_icondata['limit']='0,'.$limitnum;	
			    $old_icondata['pageurl']='';
																		
		    }
		    else
		    {	
			    $conditions = '(';
				foreach($temp_table_filed_id['id'] as $key => $value)
				{
				   $conditions .= ' '.$temp_table_filed_id['filedname'].'='.$value.' or ';
				}
				$conditions = substr($conditions,0,-3);	
				$conditions = $conditions.')';					
			    $old_icondata['conditions']=$conditions;
			    $old_icondata['order']='';				
			    $old_icondata['limit']='0,'.$limitnum;				
			 			
			}			 				 	 
		 }

		foreach($old_icondata as $key => $value)
		{
		   $iconcontent .= '  '.$key."=\'".$value."\'";
		}			 	  	
      
		$iconcontent = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$iconcontent);			

		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';
		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}		
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $iconcontent, $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename,  $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	
   
	   }
       if($action=="getTplcode")
	   {
	   $divid = $_GET['divid'];	
	   $filepath = $_GET['filepath'];
	   $filepath=str_replace(SITE_URL,"",$filepath);	

		$code= str_replace(array("\r","\n"),array('\r','\n'), read_file(ROOT_PATH.$filepath));	 
    	echo "<SCRIPT LANGUAGE=\"JavaScript\">
	    <!--
	    parent.puthtmlcode('$code');
	    //-->
	    </SCRIPT>";
	    exit;
       }	   
	   			 	   
       if($action=='getfidsonslist')
	   { 
	      $fup = $_GET['fup'];
		  $class = $_GET['class'];
		  $ctype = $_GET['ctype'];
		  $page =  $_GET['page'];
		  $Murl = SITE_URL.'/admin/'; 
	      $temparray = get_db()->tables();
		  foreach($temparray as $key => $value)
		  {
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;

			    }
			 }
		  }
	  
          header('Content-type: text/html; charset='.VIEW_CHARSET);	
		  
  		 $tables_fileds = del_empty_var(explode(",",$fup));

		 $tablename_array = array();
		 $fields_array = array();
		 $temp_fields_array = array();
		 $temp_fields_array1 = array();		 		 
         $data = array();
		 	 
         if(isset($tables_fileds[0])&&!empty($tables_fileds[0]))
		 {
		    $temp = $temp1 = array();	
		    $temp = explode("|",$tables_fileds[0]);			
            $temp = del_empty_var($temp);
			$num=1;
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(".",$value);
				if(isset($temp1[1]))
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = $temp1[1];
				}
				else
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = 0;			
				}
				$num++;
			}

		 }
	
         if(isset($tables_fileds[1])&&!empty($tables_fileds[1]))
		 {
		    $temp = $temp1 = array();	
		    $temp = explode("|",$tables_fileds[1]);			
            $temp = del_empty_var($temp);
			
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(":",$value);
				if(isset($temp1[1]))
				{
				$fields_array[$temp1[0]] = $temp1[1];
				}
				else
				{
				$fields_array[$temp1[0]] = 0;				
				}
				$temp3 = explode(".",$temp1[0]);
                $temp_fields_array1[$key] = $temp1[0];								
                $temp_fields_array[$key] = $temp3[1];				
			}
		 }



		 if(isset($tables_fileds[0])&&isset($tables_fileds[1])&&!empty($tables_fileds[0])&&!empty($tables_fileds[1]))
		 {     
			  $temp_on = '';
			  $table_pre_key = '';
			  $table_pre_value = '';

              if(count($tablename_array)==1)
			  {
			     $tables = DB_PREFIX.$tablename_array[1]['table']. ' '.$tablename_array[1]['table'];
			  }
			  else
			  {
                for($num=1;$num<=count($tablename_array);$num++)
		        {
				  if(empty($tablename_array[$num]['field'])){$tablename_array[$num]['field'] = ' ';}

                  if(isset($tablename_array[$num+1])&&$num==1)
				  {	

                  $tables.= DB_PREFIX.$tablename_array[$num]['table'] . ' '.$tablename_array[$num]['table'].' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';
				  
				  }
				  else
				  {   
					  if(isset($tablename_array[$num+1]))
					  {
	                  $tables.= ' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';						  
					  }
		  
				  }
		        }	
			  }

              foreach($fields_array as $key => $value)
		      {
			     if(empty($value))
			     {
                   $fields.= $key . ' ,';			
			     }else
			     {
                   $fields.= $key . ' as '.$value.' ,';			
			     }
		      }
  			  $fields = substr($fields, 0,-1);

			  $data =  get_model()->Page_And_S_Sql_Exe(array("table" => $tables,"fields" => $fields,"conditions" => '',"order" => '',"limit" => '20',"return" => "all","url" =>''));

		  }

           
		 $select_str = "";

		 foreach($tablename_array as $key => $value)
		 {
		    
		    foreach($tablearray[DB_PREFIX.$value['table']] as $key1 => $value1)
		    {			             
             $select_str .= '<option  value="'.$value1.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key1.'</option>';	   
		    }
			$select_str .= '<optgroup label="===================" style="color:red;"></optgroup>';	 

		 }
		 		 

		 
         $str='';
		  foreach($data['data'] as $key => $value)
		  {
		        $next='false';
		        $icon_fup = true;
				if($value[$temp_fields_array[0]])
				{
				$str.= "<div><a href=\"javascript:;\" onclick=\"changeClassName($class,this,\'".$tables_fileds[0].','.$temp_fields_array1[0].','.$value[$temp_fields_array[0]]."\',$next,$ctype ,\'$Murl\')\">".'['.$value[$temp_fields_array[0]].']'.$value[$temp_fields_array[1]]."</a></div>"; 				
				}
	
			   
		  }			  
	     $str=$str?$str:"&nbsp;";
	     echo '<script >parent.inputcontent(\''.$str.'\','.$class.',\''.$select_str.'\');</script>';
	     exit;	
       }
  
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];

		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		

		$tablename_tb = $_GET['tb'];
		
		$filed_tb = $_GET['fd'];		
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
	    $data['config'] = $this->icon_to_array;
		
        $iconfield =  del_empty_var(explode("|",$data['config']['fields']));
		$iconfielddata = array();
        foreach($iconfield as $key => $value)
		{
		   $temp = del_empty_var(explode(":",$value));
		   $iconfielddata[$temp[1]] = $temp[0];
		}
        $limitnum = del_empty_var(explode(",",$data['config']['limit']));

		if(empty($limitnum[1]))$limitnum[1]=10;
	    $limitnum = $limitnum[1];
	   
		$data['iconcontent'] = '<phpscup:icon '.$strdata.' />';
		$data['iconname'] = $iconname;	
			
	    $tablearray = array();
	    $temparray = get_db()->tables();
		foreach($temparray as $key => $value)
		{
			if($value)
			{
		        $temp_str = str_replace(DB_PREFIX,'',$value);
				$temp_array = get_db()->get_fields($value);
 		        $tablearray[$value][$value] = $temp_str; 

		        foreach($temp_array as $key1=>$value1)
				{
			     $tablearray[$value][$value.'.'.$value1] = $temp_str.'.'.$value1;
			    }
			}

		}
        $temparray = & $GLOBALS['SCup']->_get_module_list_data();
        $categorydata = array();
		foreach($temparray as $key => $value)
		{
        $appnamearray[$value['id']] = $key;
		$categorydata[$value['id']]['alias']=$value['alias'];
		$categorydata[$value['id']]['appname']=$value['appname'];
		$categorydata[$value['id']]['category']=@include(ROOT_PATH . '/data/category/category_'. $key .'.php');					
		}

        $cachearray = array();
        $cachearray['data/category/'] = get_all_dirname(ROOT_PATH . '/data/category');
        $cachearray['data/cache/'] = get_all_dirname(ROOT_PATH . '/data/cache');
        $cachearray['data/nav/'] = get_all_dirname(ROOT_PATH . '/data/nav');

        $htmlnamearray = array();
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon');
        $temparray1 = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icon.php');
		foreach($temparray1 as $key => $value)
		{

		   $htmlnamearray[$key] = $key.'.html';
		}

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $htmlnamearray[str_replace('.html','',$value)] = $value;
		   }
		}
        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}


		$code= read_file(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/'.$data['config']['htmlname'].'.html');	 


        $icontabledata = '';
        if(isset($data['config']['tablename'])&&!empty($data['config']['tablename']))
		{	
		
		    $sql_order ='';
		    $sql_limit = '';
		    $sql_conditions = '';
		    $sql_table = '';
		    $sql_field = '';
			$tableid = '';
			$sql = '';
			
		    $tempclass_name = array();					
		    $tablename_array = array();
		    $fields_array = array();
		    $fields_temp_array = array();								
		    $temp = $temp1 = array();	
		    $temp = explode("|",$data['config']['tablename']);			
            $temp = del_empty_var($temp);
			$num=1;
            foreach($temp as $key => $value)
			{
		        $temp1 = explode(".",$value);
				if(isset($temp1[1]))
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = $temp1[1];
				}
				else
				{
				$tablename_array[$num]['table'] = $temp1[0];
				$tablename_array[$num]['field'] = 0;			
				}
				$num++;
			}
            foreach($changeClassName as $key => $value )
			{
  		       if($value['table']==$data['config']['tablename'])
			   {
			     $categorydata =  $value['name'];
				 $tempclass_name = $value;
			     $fields_array[$value['filed1']] = 0;
			     $fields_array[$value['filed2']] = 0;
				 $temp = explode(".",$value['filed1']);
				 $fields_temp_array[1]= $temp[1];
				 $temp = explode(".",$value['filed2']);
				 $fields_temp_array[2]= $temp[1];				 				 			   
			   }
			}
			
            if(count($tablename_array)==1)
			{
			   $sql_table = DB_PREFIX.$tablename_array[1]['table']. ' '.$tablename_array[1]['table'];
			}
			 else
			{
              for($num=1;$num<=count($tablename_array);$num++)
		      {
				  if(empty($tablename_array[$num]['field'])){$tablename_array[$num]['field'] = ' ';}

                  if(isset($tablename_array[$num+1])&&$num==1)
				  {	

                  $sql_table.= DB_PREFIX.$tablename_array[$num]['table'] . ' '.$tablename_array[$num]['table'].' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';
				  
				  }
				  else
				  {   
					  if(isset($tablename_array[$num+1]))
					  {
	                  $sql_table.= ' LEFT JOIN '.DB_PREFIX.$tablename_array[$num+1]['table'] . ' '.$tablename_array[$num+1]['table'].' ON '. $tablename_array[$num]['table'] .'.'.$tablename_array[$num]['field'].'='. $tablename_array[$num+1]['table'] .'.'.$tablename_array[$num+1]['field'].' ';						  
					  }
		  
				  }


		      }	
			  
			}

            foreach($fields_array as $key => $value)
		    {
			   if(empty($value))
			   {
                $sql_field.= $key . ' ,';			
			   }else
			   {
                $sql_field.= $key . ' as '.$value.' ,';			
			   }
		    }
  			$sql_field = substr($sql_field, 0,-1);
		
			
            if(isset($data['config']['order']))
		    {
		      $sql_order = ''.$data['config']['order'];		
		    }
            if(isset($data['config']['limit']))
		    {
		      $sql_limit = ''.$data['config']['limit'];		
		    }
            if(isset($data['config']['conditions']))
		    {
		      $sql_conditions = ''.$data['config']['conditions'];		
		    }

		    $TB_icon = &$this->_model('icon');		
		    $tempdata = $TB_icon->iconshow($sql_table,$sql_field,$sql_conditions, $sql_order,$sql_limit);

			foreach($tempdata as $key => $value)
			{
			    if(isset($value[$fields_temp_array[1]])&&!empty($value[$fields_temp_array[1]]))
				{
			    $icontabledata .= '<div id="div_'.$tempclass_name['table'].'_'.$tempclass_name['filed1'].'_'.$value[$fields_temp_array[1]].'"><input type="checkbox" name="fids[]" value="'.$tempclass_name['table'].','.$tempclass_name['filed1'].','.$value[$fields_temp_array[1]].'" checked="" onclick="removeFid(this);">  <font color="#232323"> &gt; '.$categorydata.' &gt; ['.$value[$fields_temp_array[1]].']'.$value[$fields_temp_array[2]].'</font></div>';				
				}else
				{
				$icontabledata .= '';
				}
			
			}
       
		}
		$is_fenorxin = 1;
		if(isset($data['config']['conditions'])&&!empty($data['config']['conditions'])&&!strstr($data['config']['conditions'],'cat_id=')&&strstr($data['config']['conditions'],'id='))
		{
			$is_fenorxin = 0;
		}

        $this->assign('is_fenorxin', $is_fenorxin);		
        $this->assign('icontabledata', $icontabledata);
	
        $this->assign('code', $code);
        $this->assign('htmlname', $data['config']['htmlname']);
				
        $this->assign('changeClassName', $changeClassName);
		
        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('tablearray', $tablearray);
        $this->assign('tablename_array', $tablename_array);
				
        $this->assign('tablename', DB_PREFIX.$data['config']['tablename']);
		     
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));
	    $this->assign('categorydata', $categorydata);
	    $this->assign('iconfielddata', $iconfielddata);
	    $this->assign('limitnum', $limitnum);
		
	    $this->assign('data', $data);
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
						
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_viewmanagetableedit.view.php');
    }




    function viewmanagecacheedit()
    {

        $changeClassName = array();
        $edit_url = '';

        $temparray = & $GLOBALS['SCup']->_get_module_list_data();
        $categorydata = array();
		foreach($temparray as $key => $value)
		{
		$categorydata['category_'.$value['appname'].'.php']['name']=$value['alias'];
		$categorydata['category_'.$value['appname'].'.php']['appname']=$value['appname'];					
		}

		
        $cachearray = array();
        $cachearray['data/category/'] = get_all_dirname(ROOT_PATH . '/data/category');
        $cachearray['data/cache/'] = get_all_dirname(ROOT_PATH . '/data/cache');
        $cachearray['data/nav/'] = get_all_dirname(ROOT_PATH . '/data/nav');
 
		foreach($cachearray as $key =>$value)
		{  
		   if($key == 'data/category/')
		   {
		        foreach($value as $key1 =>$value1)
		       {
			      if(isset($categorydata[$value1]['appname'])&&!empty($categorydata[$value1]['appname']))
				  {
		        $changeClassName[] = array('name' =>$categorydata[$value1]['appname'],
		                                   'alias' =>$categorydata[$value1]['name'],
		                                   'type' =>'cache',
			                               'dir' =>$key.$value1,/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'cat_id',
			                               'showfileds2' =>'cat_name',			   			   			   
	                                       );
				  }else
				  {
				   $temp = str_replace(array('category_','.php'),array('',''),$value1);
		        $changeClassName[] = array('name' =>$temp,
		                                   'alias' =>$temp,
		                                   'type' =>'cache',
			                               'dir' =>$key.$value1,/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'cat_id',
			                               'showfileds2' =>'cat_name',			   			   			   
	                                       );  
				  }					   
		       }		   
		   
		   }
	   
		   else if($key == 'data/nav/')
		   {
		        foreach($value as $key1 =>$value1)
		       {
		        $changeClassName[] = array('name' =>'nav'.$key1,
		                                   'alias' =>'导航['.$value1.']',
		                                   'type' =>'cache',
			                               'dir' =>$key.$value1,/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'name',
			                               'showfileds2' =>'link',			   			   			   
	                                       );
		       }
			  		   
		   
		   }
		   else if($key == 'data/cache/')
		   {
		        foreach($value as $key1 =>$value1)
		       {
			         if(strstr($value1,'links'))
		             {
		                $changeClassName[] = array('name' =>'links'.$key1,
		                                   'alias' =>'友情链接['.$value1.']',
		                                   'type' =>'cache',
			                               'dir' =>$key.$value1,/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'name',
			                               'showfileds2' =>'url',			   			   			   
	                                       );
										   

		             }else if (strstr($value1,'rollpic'))
					 {
		                $changeClassName[] = array('name' =>'links'.$key1,
		                                   'alias' =>'滚动图片['.$value1.']',
		                                   'type' =>'cache',
			                               'dir' =>$key.$value1,/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'name',
			                               'showfileds2' =>'images_url',			   			   			   
	                                       );
										   					 
					 }

		       }		   
		   
		   }
		   
		}	
			        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $temp_data = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$value);
		    $icondataarray[str_replace('.icon','',$value)]['type'] = $temp_data['type'];
		    $icondataarray[str_replace('.icon','',$value)]['description'] = $temp_data['description'];						
		    $icondataarray[str_replace('.icon','',$value)]['file'] = $value;
			unset($temp_data);
		   }
		}

		foreach($icondataarray as $key =>$value)
		{  
		   if($value['type'] == 'data')
		   {

		        $changeClassName[] = array('name' =>$key,
		                                   'alias' =>$value['description'],
		                                   'type' =>'icon',
			                               'dir' =>'scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$value['file'],/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'datakey',
			                               'showfileds2' =>'datavalue',			   			   			   
	                                       );	   
		        
		   }		   
		   if($value['type'] == 'file')
		   {

		        $changeClassName[] = array('name' =>$key,
		                                   'alias' =>$value['description'],
		                                   'type' =>'icon',
			                               'dir' =>'scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$value['file'],/*这个要相对根目录的路径*/
			                               'fileds' =>'',
			                               'showfileds1' =>'upfile',
			                               'showfileds2' =>'description',			   			   			   
	                                       );	   
		   
		   }	
		   
		}	

	
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
	   if($action=='post')
	   {
		 $pagename = $_POST['pagename'];		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];	   
	     $fids = $_POST['fids'];		 
	     $tplpath = $_POST['tplpath'];		 
	     $tplpart_1 = $_POST['tplpart_1'];		 
	     $data = $_POST['data'];
	     $mokuai = $_POST['mokuai'];


		 
		 $strdata = $this->filtrate($strtempdata);	 
         $this->icon_to_array($strdata);
	     $old_icondata = $this->icon_to_array;

		 $fields_str = '';
		 if(isset($data)&&!empty($data))
		 {
		   foreach($data as $key => $value)
		   {
		     $fields_str .= $value['datavalue'].':'.$value['datakey'].'|'; 
		   }
		 }


	     $cur_changeclassname = array();

		 foreach($changeClassName as $key => $value)
		 {
			 if($value['name'] == $fids[0])
			 {
		         $cur_changeclassname = $value;
			 }
		 }

		 if($cur_changeclassname['type']=='icon')
		 {
		    $old_icondata['iconfields'] = $fields_str;
			$file_name = basename($cur_changeclassname['dir']);
		    if(strpos($file_name,'.icon'))
		    {
		      $old_icondata['icondata'] = str_replace('.icon','',$file_name);
		    }			
					  
		 }else
		 {
		    $old_icondata['cachedatadir'] = $cur_changeclassname['dir'];	
		    $old_icondata['cachefields'] = $fields_str;					  
		 }		 
		 
		 $old_icondata['htmlname'] = str_replace('.html','',basename($tplpath));
			 	
         if($mokuai==1)
		 {
  		    $temp_html_name = del_empty_var(explode(".",$old_icondata['htmlname']));
		    $old_icondata['htmlname'] = $temp_html_name[0];			
		    $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		    $icon_dir = ROOT_PATH . $dir;
		    $iconfile = $old_icondata['htmlname'].'.'.time().'.html';
		    $iconfilename = $old_icondata['htmlname'].'.'.time().'';
		    $old_icondata['htmlname'] = $iconfilename;			
	        $temparray = get_all_dirname($icon_dir);
            $is = 1;
	        foreach($temparray as $key => $value)
		    {
		      if($value==$iconfile)
		      {
              $is = 0;break;
		      }	
            }
			
		    if($is)
		    {
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }		
		    }
		    else
		    {		
		      $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新提交','url'=>'','title'=>'Notice'));
		      $notice ->display();			
		    }
		     
		 }else if ($mokuai==0)
		 {

		        $dir = '/scup/view/'.VIEW_TYPE.'/icon';
		        $icon_dir = ROOT_PATH . $dir;
		        $iconfile = $old_icondata['htmlname'].'.html';
		        $iconfilename = $old_icondata['htmlname'];		 
                $iconhtml = stripslashes($tplpart_1);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"),$iconhtml);				
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$iconfilename;
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	            write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	        write_file($icon_dir."/".$iconfile,$iconhtml);	
   	            if(!is_writable($icon_dir."/".$iconfile))
		        {	
		        $notice = &get_message(array('msg'=>$icon_dir."/".$iconfilename.".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		        $notice ->display();		
	            }			 
		 }

		foreach($old_icondata as $key => $value)
		{
		   $iconcontent .= '  '.$key."=\'".$value."\'";
		}			 	  	

		$iconcontent = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$iconcontent);			

		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';
		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}		
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $iconcontent, $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename,  $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	
   
	   }
       if($action=="getTplcode")
	   {
	   $divid = $_GET['divid'];	
	   $filepath = $_GET['filepath'];
	   $filepath=str_replace(SITE_URL,"",$filepath);	

		$code= str_replace(array("\r","\n"),array('\r','\n'), read_file(ROOT_PATH.$filepath));	 
    	echo "<SCRIPT LANGUAGE=\"JavaScript\">
	    <!--
	    parent.puthtmlcode('$code');
	    //-->
	    </SCRIPT>";
	    exit;
       }	   
	   			 	   
       if($action=='getfidsonslist')
	   { 
	      $fup = $_GET['fup'];
		  $class = $_GET['class'];
		  $ctype = $_GET['ctype'];
		  $page =  $_GET['page'];
		  $Murl = SITE_URL.'/admin/'; 
	      $temparray = array();
	      $temparray1 = array();
		    
		  foreach($changeClassName as $key => $value)
		  {
			if($value['name'] == $fup)
			{
		        $temparray = $value;
			 }
		  }
		  	  
		  if($temparray['type']=='icon')
		  {
          $temparray1 = include(ROOT_PATH .'/' .$temparray['dir']);	
		  $temparray1 = $temparray1['data'];	  
		  }else
		  {
          $temparray1 = include(ROOT_PATH .'/' .$temparray['dir']);			  
		  }	  
          header('Content-type: text/html; charset='.VIEW_CHARSET);

		 $select_str = "";		 
		 foreach($temparray1 as $key => $value)
		 {  
		    if(is_array($value)&&!empty($value))
			{
			    foreach($value as $key1 => $value1)
				{
				     if(is_array($value1)&&!empty($value1))
					 {
					     foreach($value1 as $key2 => $value2)
				         {
                             $select_str .= '<option  value="'.$key1.'.'.$key2.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key1.'.'.$key2.'</option>';					 
				         } 
					 }else
					 {
                       $select_str .= '<option  value="'.$key1.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key1.'</option>';					 
					 }
				}
			}
			break;          
	   
		 }
 
          $str='';
		  if(is_array($temparray1)&&!empty($temparray1))
		  {
		        $next='false';
		        $icon_fup = true;
				$temp_str = ''; 
				foreach($temparray1 as $key => $value)
				{
				    $temp_str .= '['.$key .']'.$value[$temparray['showfileds1']] .'=>'.$value[$temparray['showfileds2']].'<br/>';					
				}
			    if($temparray['type']=='icon')
			    {
			    $temp_str .= '<a href="?app=icon&act=editicondata&id='.$temparray['name'].'" target="_blank"><font color="red">[edit]</font></a>';	
			    }				
				$str.= "<div><a href=\"javascript:;\" onclick=\"changeClassName($class,this,\'".$fup."\',$next,$ctype ,\'$Murl\')\">(".$temp_str.")</a></div>";			   
		  }			  
	     $str=$str?$str:"&nbsp;";
	     echo '<script >parent.inputcontent(\''.$str.'\','.$class.',\''.$select_str.'\');</script>';
	     exit;	
       }		
	
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];

		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
	    $data['config'] = $this->icon_to_array;

		$cachedir = '';
		$cachefields = '';			
        if(isset($data['config']['icondata'])&&!empty($data['config']['icondata']))
		{
		
		  $cachedir = 'scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$data['config']['icondata'].'.icon';
		  $cachefields = $data['config']['iconfields'];		  
		}
        if(isset($data['config']['cachedatadir'])&&!empty($data['config']['cachedatadir']))
		{
		  $cachedir = $data['config']['cachedatadir'];
		  $cachefields = $data['config']['cachefields'];		  
		}		
				
        $iconfield =  del_empty_var(explode("|",$cachefields));
		$iconfielddata = array();
        foreach($iconfield as $key => $value)
		{
		   $temp = del_empty_var(explode(":",$value));
		   $iconfielddata[$temp[1]] = $temp[0];
		}
		
	    $cur_changeclassname = array();
	    $cur_cachedata = array();
  
		foreach($changeClassName as $key => $value)
		{
			if($value['dir'] == $cachedir)
			{
		        $cur_changeclassname = $value;
			}
		}

		if($cur_changeclassname['type']=='icon')
		{
		  
          $cur_cachedata = include(ROOT_PATH .'/' .$cur_changeclassname['dir']);	
		  $cur_cachedata = $cur_cachedata['data'];	  
		}else if($cur_changeclassname['type']=='cache')
		{
          $cur_cachedata = include(ROOT_PATH .'/' .$cur_changeclassname['dir']);			  
		}else
		{
		  $cur_cachedata = array();
		}	  


		 $cur_select_str = "";		 
		 foreach($cur_cachedata as $key => $value)
		 {  
		    if(is_array($value)&&!empty($value))
			{
			    foreach($value as $key1 => $value1)
				{
				     if(is_array($value1)&&!empty($value1))
					 {
					     foreach($value1 as $key2 => $value2)
				         {
                             $cur_select_str .= '<option  value="'.$key1.'.'.$key2.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key1.'.'.$key2.'</option>';					 
				         } 
					 }else
					 {
                       $cur_select_str .= '<option  value="'.$key1.'">&nbsp;|&nbsp;&nbsp;&nbsp;'.$key1.'</option>';					 
					 }
				}
			}
			break;          
	   
		 }
		 
		$temp_str = ''; 
		foreach($cur_cachedata as $key => $value)
		{
			$temp_str .= '['.$key .']'.$value[$cur_changeclassname['showfileds1']] .'=>'.$value[$cur_changeclassname['showfileds2']].'<br/>';					
		}
				 
        if(isset($cur_changeclassname['name'])&&!empty($cur_changeclassname['name']))
		{
			if($cur_changeclassname['type']=='icon')
			{
			   $edit_url = '<a href="?app=icon&act=editicondata&id='.$cur_changeclassname['name'].'" target="_blank"><font color="red">[edit]</font></a>';	
			}
		$icontabledata .= '<div id="div_'.$cur_changeclassname['name'].'"><input type="checkbox" name="fids[]" value="'.$cur_changeclassname['name'].'" checked="" onclick="removeFid(this);">  <font color="#232323"> &gt; '.$cur_changeclassname['alias'].' &gt; '.$temp_str.$edit_url.'</font></div>';					
		}else
		{
		$icontabledata = '';			
		}
	   
	   
		$data['iconcontent'] = '<phpscup:icon '.$strdata.' />';
		$data['iconname'] = $iconname;	
			
        $htmlnamearray = array();
        $temparray = array();
        $temparray1 = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon');
        $temparray1 = include(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icon.php');
		foreach($temparray1 as $key => $value)
		{
		   $htmlnamearray[$key] = $key.'.html';
		}

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $htmlnamearray[str_replace('.html','',$value)] = $value;
		   }
		}
        
        $icondataarray = array();
        $temparray = array();
        $temparray = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata');
	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[str_replace('.icon','',$value)] = $value;
		   }
		}


		$code= read_file(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/'.$data['config']['htmlname'].'.html');	 
		
        $this->assign('icontabledata', $icontabledata);
	
        $this->assign('code', $code);
        $this->assign('htmlname', $data['config']['htmlname']);		

        $this->assign('changeClassName', $changeClassName);

        $this->assign('icondataarray', $icondataarray);
        $this->assign('htmlnamearray', $htmlnamearray);
        $this->assign('cachearray', $cachearray);
        $this->assign('appnamearray', $appnamearray);
        $this->assign('cur_select_str', $cur_select_str);

		     
        $this->assign('viewdata', get_all_dirname(ROOT_PATH . '/scup/view'));
	    $this->assign('categorydata', $categorydata);
	    $this->assign('iconfielddata', $iconfielddata);
		
	    $this->assign('data', $data);
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
						
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('icon_viewmanagecacheedit.view.php');
    }






    function viewmanageactiveedit()
	{
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];
		
		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
		
	    $iconconfig = $this->icon_to_array;

        $start_end_time =  del_empty_var(explode(",",$iconconfig['activetime']));
		$iconconfig['activetime_start'] = $start_end_time[0];
		$iconconfig['activetime_end'] = $start_end_time[1];

        $tempactivearray = array();
        $activearray = array();		
        $tempactivearray['after'] = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/active/after');
        $tempactivearray['before'] = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/active/before');
        $tempactivearray['period'] = get_all_dirname(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/active/period');
		foreach($tempactivearray as $key => $value)
		{
		     foreach($value as $key1 => $value1)
			 {
			   $activearray[$key][$key1] = str_replace(array('.active.'.$key.'.php'),array(''),$value1);
			 }		   	     
		}
	    $this->assign('activearray', $activearray);
		
	    $this->assign('data', $iconconfig);

	    $this->assign('iconname', $iconname);
			
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
							
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
			
        $this->display('icon_viewmanageactiveedit.view.php');	
	}
	
    function viewmanageactiveeditpost()
    {

		 $pagename = $_POST['pagename'];
		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];
		 		 	
		 $strdata = $this->filtrate($strtempdata);
		 $this->icon_to_array($strdata);
		
	     $iconconfig = $this->icon_to_array;		 	 
	     $data = $_POST['data'];

		 if(!empty($data['activetime_start'])&&!empty($data['activetime_end']))
		 {
		    $data['activetime'] = $data['activetime_start'].','.$data['activetime_end'];
		 }else
		 {
		    $data['activetime'] = '';		 
		 }
		 unset($data['activetime_start'],$data['activetime_end']);

         $tempdata = $data + $iconconfig;
		 $tempdata = del_empty_var($tempdata); 
  

         $data['config'] = $tempdata;
         $data['iconcontent']='';
		 		 			 
		 foreach($data['config'] as $key => $value)
		 {
			 $data['iconcontent'] .= '  '.$key."=\'".$value."\'";
		 }			 	  	
	
		 $data['iconcontent'] = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$data['iconcontent']);			

		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';

		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}
		
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $data['iconcontent'], $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename, $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	


    }

    function viewmanagelabeledit()
	{
       if(!isset($_GET['action']))$_GET['action']='';
	   $action = $_GET['action'];
	   if($action=='post')
	   {
		 $pagename = $_POST['pagename'];		 
		 $strtempdata = $_POST['strtempdata'];		 
		 $fromurl = $_POST['fromurl'];	   
	 
	     $labels = $_POST['labels'];
		 $labels = str_replace("\t","   &nbsp;  &nbsp;",$labels);
		 $labels = str_replace("\r","",$labels);
		 $labels = str_replace("\n","",$labels);		 
		 $strdata = $this->filtrate($strtempdata);	 
         $this->icon_to_array($strdata);
	     $old_icondata = $this->icon_to_array;
         $old_icondata['labels'] = $labels;

        $iconcontent='';
		foreach($old_icondata as $key => $value)
		{
		   $iconcontent .= '  '.$key."=\'".$value."\'";
		}			 	  	

		$iconcontent = str_replace(array('&quot;','&#39;','\\'),array('"',"'",''),$iconcontent);					
		$filename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/' . $pagename;
		$savefilename = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/' . $pagename;
		$savedir = ROOT_PATH .'/scup/view/'.VIEW_TYPE. '/tempview/';
		$tempfilename = '';				
		if(is_file($savefilename) && @ filemtime($savefilename) > @ filemtime($filename))
		{			
		     $tempfilename = $savefilename;				   			
		}
		else
		{
		     $tempfilename = $filename;					
		}
				
		$fileContent = "";
		if (!($fileContent = file_get_contents($tempfilename))) 
		{
				return false;
		}
				
		$fileContent = preg_replace('/^(\xef\xbb\xbf)/', '', $fileContent); //EFBBBF
		$fileContent = str_replace($strdata, $iconcontent, $fileContent);
		
		if (!file_exists($savefilename)) {
				get_dir($savedir);
		}
		
		if (!file_put_contents($savefilename,  $fileContent)) {
			return false;
		}

		$notice = &get_message(array('msg'=>'修改成功','url'=>$this->_urldecode($fromurl),'title'=>'Notice'));
		$notice ->display();	
   
	   }
		
		
		$iconname = $_GET['iconname'];
		
		$pagename = $_GET['pagename'];	
			
		$strdata = $_GET['data'];
		
		$weburl = $_GET['weburl'];
		
		$weburl= $this->_urldecode($weburl);
		$fromurl = $weburl;				
		$weburl= $this->_urlencode($weburl);
					
		$divwidth = $_GET['divwidth'];
				
		$divheight = $_GET['divheight'];
		
		$strtempdata = $strdata;
		$urlstr="&weburl={$weburl}&iconname={$iconname}&pagename={$pagename}&data={$strdata}&divwidth={$divwidth}&divheight={$divheight}";
		
		$strdata = $this->filtrate($strdata);	

		$this->icon_to_array($strdata);
		
	    $iconconfig = $this->icon_to_array;

		
	    $this->assign('data', $iconconfig);

	    $this->assign('iconname', $iconname);
			
	    $this->assign('weburl', $weburl);
	    $this->assign('fromurl', $fromurl);	
							
	    $this->assign('urlstr', $urlstr);
		
        $this->assign('pagename', $pagename);			
        $this->assign('strtempdata', $strtempdata);	
	    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
			
        $this->display('icon_viewmanagelabeledit.view.php');	
	}

    function liconcontent()
    {
		 $data = array();
		 
	     $id = $_GET['id'];
		 $data['status'] = $_GET['s'];
		 if($data['status']==1)
		 {
		 $data['status'] = 0;
		 }
		 else
		 {
		 $data['status'] = 1;		 
		 }
		 
		 $TB_view = &$this->_model('view');  	 		
		 $TB_view->editstatus($id,$data); 
	 
		 $this->index();			  

    }



    function del()
    {
		$id= intval($_GET['id']);		

		$TB_icon = &$this->_model('icon'); 		
		$TB_icon->del($id);
				      
        $this->index();    
    }	

    function iconhtml()
    {	
		$dir = '/scup/view/'.VIEW_TYPE.'/icon';
		$icon_dir = ROOT_PATH . $dir;
        $iconhtmlarray = array();
	    $temparray = get_all_dirname($icon_dir);
        $temparray1 = include($icon_dir.'/icon.php');

		foreach($temparray1 as $key => $value)
		{
		   $iconhtmlarray[$key.'.html']['name'] = $key;
		   $iconhtmlarray[$key.'.html']['dir'] = $dir.'/'.$value['name'].'.html';
		   $iconhtmlarray[$key.'.html']['data'] =  str_replace(array("<",">"),array("&lt;","&gt;"),$value['html']);
		}
    

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.html'))
		   {
		    $iconhtmlarray[$value]['name'] = str_replace('.html','',$value);
		    $iconhtmlarray[$value]['dir'] = $dir.'/'.$value;
		    $iconhtmlarray[$value]['data'] =  str_replace(array("<",">"),array("&lt;","&gt;"),read_file($icon_dir.'/'.$value));

		   }
		}


        $this->assign('data', $iconhtmlarray);

        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('icon_html_list.view.php');
    }
    function iconhtmladd()
    {	


        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('icon_html_add.view.php');
    }

    function editiconhtml()
    {	
		$id= $_GET['id'];
		$dir = '/scup/view/'.VIEW_TYPE.'/icon';
		$icon_dir = ROOT_PATH . $dir;		

		$data = array();
        $data['html'] =  str_replace(array("<",">"),array("&lt;","&gt;"),read_file(ROOT_PATH . $dir.'/'.$id.'.html'));

		if(!empty($data['html']))
		{
         $data['name'] = $id;		
		}
		else
		{
        $temparray = include($icon_dir.'/icon.php');

		   foreach($temparray as $key => $value)
		   {
		   $data['name'] = $temparray[$id]['name'];
		   $data['html'] =  str_replace(array("<",">"),array("&lt;","&gt;"),$temparray[$id]['html']);
		   }
    		
		
		}



        $this->assign('data', $data);
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('icon_html_edit.view.php');
    }

	function editposticonhtml() 
	{

		$dir = '/scup/view/'.VIEW_TYPE.'/icon';
		$icon_dir = ROOT_PATH . $dir;
		
		$data = $_POST['data'];

        $id = $_POST['id'];


        $is = 1;
		if($id != $data['name'])
		{	
	       $temparray = get_all_dirname($icon_dir);		
	       foreach($temparray as $key => $value)
		   {
		     if($value==$data['name'].'.html')
		     {
             $is = 0;break;
		     }
	
           }

		   if($is)
		   {
		   
			   if(!is_dir($icon_dir.'/'.$id.'.html')&&file_exists($icon_dir.'/'.$id.'.html'))
		       {
		           if(!is_dir($icon_dir.'/'.$id.'.html')&&file_exists($icon_dir.'/'.$id.'.html'))
		           {
		             del_file($pic_dir);	
		           }				   
		       }		   		
		   }
        }

		if($is)
		{
                $iconhtml = stripslashes($data['html']);
	            $iconhtml =str_replace(array("&lt;","&gt;"),array("<",">"),$iconhtml);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"), $iconhtml);								
                $iconhtmlarray = include($icon_dir.'/icon.php');
				unset($iconhtmlarray[$id]);
		        $iconhtmlarray[$data['name']]['name'] =$data['name'];
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	        write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	    write_file($icon_dir."/".$data['name'].".html",$iconhtml);	
   	       if(!is_writable($icon_dir."/".$data['name'].".html"))
		    {	
		     $notice = &get_message(array('msg'=>$icon_dir."/".$data['name'].".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		     $notice ->display();		
	        }		
		   $this->iconhtml();
		}
		else
		{
		
		 $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新输入','url'=>'?app=icon&act=icondataadd&type=file','title'=>'Notice'));
		 $notice ->display();			
		}


				
	}

	function addposticonhtml() 
	{

		$dir = '/scup/view/'.VIEW_TYPE.'/icon';
		$icon_dir = ROOT_PATH . $dir;
		
		$data = $_POST['data'];



	    $temparray = get_all_dirname($icon_dir);
        $is = 1;
	    foreach($temparray as $key => $value)
		{
		   if($value==$data['name'].'.html')
		   {
             $is = 0;break;
		   }
	
        }

		if($is)
		{
                $iconhtml = stripslashes($data['html']);
	            $iconhtml =str_replace(array("&lt;","&gt;"),array("<",">"),$iconhtml);
		        $iconhtml = str_replace(array('&quot;','&#39;'),array('"',"'"), $iconhtml);					
                $iconhtmlarray = include($icon_dir.'/icon.php');
		        $iconhtmlarray[$data['name']]['name'] =$data['name'];
                $iconhtmlarray[$data['name']]['html'] =$iconhtml;
				$iconhtmlarray[$data['name']]['config'] =array();
	        write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");
     	    write_file($icon_dir."/".$data['name'].".html",$iconhtml);	
   	       if(!is_writable($icon_dir."/".$data['name'].".html"))
		    {	
		     $notice = &get_message(array('msg'=>$icon_dir."/".$data['name'].".html模板生成失败,有可能是目录权限不可写,请手工创建一个,复制代码进去",'url'=>'','title'=>'Notice'));
		     $notice ->display();		
	        }		
		   $this->iconhtml();
		}
		else
		{
		
		 $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新输入','url'=>'?app=icon&act=icondataadd&type=file','title'=>'Notice'));
		 $notice ->display();			
		}


				
	}
  	
    function deliconhtml()
    {
		$id= $_GET['id'];	
		$dir = '/scup/view/'.VIEW_TYPE.'/icon';
		$icon_dir = ROOT_PATH . $dir;


       $iconhtmlarray = include($icon_dir.'/icon.php');

	   unset($iconhtmlarray[$id]);  

	   write_file($icon_dir.'/icon.php', "<?php \nreturn " . var_export($iconhtmlarray , true) . ";\n?>");

			   if(!is_dir($icon_dir.'/'.$id.'.html')&&file_exists($icon_dir.'/'.$id.'.html'))
		       {
		           del_file($icon_dir.'/'.$id.'.html');	
		       }
	
		$this->iconhtml();
    }

    function icondata()
    {	
		$dir = '/scup/view/'.VIEW_TYPE.'/icon/icontempdata';
		$icon_dir = ROOT_PATH . $dir;
        $icondataarray = array();
	    $temparray = get_all_dirname($icon_dir);

	    foreach($temparray as $key => $value)
		{
		   if(strpos($value,'.icon'))
		   {
		    $icondataarray[$value]['name'] = str_replace('.icon','',$value);
		    $icondataarray[$value]['dir'] = $dir.'/'.$value;
			$temp_data = include($icon_dir.'/'.$value);
		    $icondataarray[$value]['data'] =  "<?php \nreturn " . var_export($temp_data['data'] , true) . ";\n?>";
		    $icondataarray[$value]['description'] = $temp_data['description'] ;
		   }
		}

        $this->assign('data', $icondataarray);

        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('icon_data_list.view.php');
    }

    function icondataadd()
    {	
	    if(!isset($_GET['type']))
		{
		$_GET['type'] = '';
		}
        $type = $_GET['type'];

        $this->assign('idtime', time());
        $this->assign('type', $type);
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('icon_data_add.view.php');
    }

    function editicondata()
    {	
		$id= $_GET['id'];	
		$filedir = ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$id.'.icon';
        $icondata = include($filedir);
        $type = $icondata['type'];
	    $data = $icondata['data'];
	    $description = $icondata['description'];
		$idtime ='';
		if($type =='file')
		{
         foreach($data as $key =>$value)
		 {
		    if(isset($value['upfile']))
			{
               $temp = explode('/', $value['upfile']); 
			   if(isset($temp[1])&&!empty($temp[1]))
				{
                  $idtime = $temp[1];
			      break;	
			    }
			 	
		    }

		 }
        }

        $this->assign('idtime', $idtime);
        $this->assign('id', $id);
        $this->assign('type', $type);
        $this->assign('data', $data);
        $this->assign('description', $description);

        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', $GLOBALS['Lang']->_get_lang_var(SITE_TITLE));
        $this->assign('page_description', $GLOBALS['Lang']->_get_lang_var(SITE_DESCRIPTION));
        $this->assign('page_keywords', $GLOBALS['Lang']->_get_lang_var(SITE_KEYWORDS));			
        $this->assign('site_url',SITE_URL);		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
        $this->display('icon_data_edit.view.php');
    }

/*
icondata的数据类型有file文件类型，data数据类型
*/
    function delicondata()
    {
		$id= $_GET['id'];	
		$filedir = ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$id.'.icon';

        $icondata = include($filedir);
		 if($icondata['type']=='file')
		{
		     foreach($icondata['data'] as $key => $value)
		     {
			   $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $value['upfile'];
			   if(!is_dir($filedir)&&file_exists($filedir))
		       {
		           del_file($filedir);	
		       }			 
		     }	
		}
			   if(!is_dir($filedir)&&file_exists($filedir))
		       {
		           del_file($filedir);	
		       }		

		$this->icondata();
    }


    function icondataaddpost()
    {
        $data = $_POST['data'];
        $type = $_POST['type'];
        $name = $_POST['name'];
        $description = $_POST['description'];


		$dir = '/scup/view/'.VIEW_TYPE.'/icon/icontempdata';
		$icon_dir = ROOT_PATH . $dir;
        $icondataarray = array();
	    $temparray = get_all_dirname($icon_dir);
        $is = 1;
	    foreach($temparray as $key => $value)
		{
		   if($value==$name.'.icon')
		   {
             $is = 0;break;
		   }
		}
        
		if($type =='file')
		{
		    if(!$is)
			{
	            foreach($data as $key => $value)
		        {
				   $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $value['upfile'];
			       if(!is_dir($pic_dir)&&file_exists($pic_dir))
		           {
		           del_file($pic_dir);	
		           }				
		        }
			
			}
		
		}
        
		if($is)
		{
		
		$temp_array = array('type'=>$type,'data'=>$data,'description'=>$description);
		$cache_filename = ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$name.'.icon';		
	    write_file($cache_filename, "<?php \nreturn " . var_export($temp_array , true) . ";\n?>");
		$this->icondata();
		}
		else
		{
		 $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新输入','url'=>'?app=icon&act=icondataadd&type=file','title'=>'Notice'));
		 $notice ->display();		
		}
         
    }



    function icondataeditpost()
    {
		$id = $_POST['id'];
        $data = $_POST['data'];
        $type = $_POST['type'];
        $name = $_POST['name'];
        $description = $_POST['description'];
        $is = 1;
        if($id != $name)
		{
		    $dir = '/scup/view/'.VIEW_TYPE.'/icon/icontempdata';
		    $icon_dir = ROOT_PATH . $dir;
            $icondataarray = array();
	        $temparray = get_all_dirname($icon_dir);

	        foreach($temparray as $key => $value)
		   {
		      if($value==$name.'.icon')
		      {
               $is = 0;break;
		      }
		   }
		   if($is)
		   {
			   if(!is_dir(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$id.'.icon')&&file_exists(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$id.'.icon'))
		       {
		           del_file(ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$id.'.icon');	
		       }		   
		   
		   }
		}

		if($type =='file')
		{
		    if(!$is)
			{
	            foreach($data as $key => $value)
		        {
				   $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $value['upfile'];
			       if(!is_dir($pic_dir)&&file_exists($pic_dir))
		           {
		           del_file($pic_dir);	
		           }				
		        }
			
			}
		
		}
        
		if($is)
		{
		
		$temp_array = array('type'=>$type,'data'=>$data,'description'=>$description);
		$cache_filename = ROOT_PATH . '/scup/view/'.VIEW_TYPE.'/icon/icontempdata/'.$name.'.icon';		
	    write_file($cache_filename, "<?php \nreturn " . var_export($temp_array , true) . ";\n?>");
		$this->icondata();
		}
		else
		{
		 $notice = &get_message(array('msg'=>'Icondata名称有相同，请重新输入','url'=>'?app=icon&act=icondataadd&type=file','title'=>'Notice'));
		 $notice ->display();		
		}
         
    }


    function upfile()
    {
        if(!isset($_POST["action"]))
		{
		  $_POST["action"]='';
		}
        if(!isset($_GET['jsfun']))
		{
		  $_GET['jsfun']='';
		}		
        if(!isset($_GET['uppic']))
		{
		  $_GET['uppic']='';
		}	
        if(!isset($_GET["picurl"]))
		{
		 $_GET["picurl"] ='';
		}			
        if(!isset($_GET['edit']))
		{
		  $_GET['edit']='';
		}			
        if(!isset($_GET['id']))
		{
		  $_GET['id']='';
		}			
				
        $action = $_POST["action"];		
		$jsfun = $_GET['jsfun'];
		$uppic = $_GET['uppic'];
		$picurl = $_GET["picurl"];
		$edit = $_GET['edit'];
        $id = $_GET['id'];

			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }				 
		       }								
		if($action == 'post')
		{
		    $jsfun = $_POST['jsfun'];
		    $uppic = $_POST['uppic'];		
		     $edit = $_POST["edit"];
		     $picurl = $_POST["picurl"];
			    $id = $_POST['id'];	
		       $filedname = trim(str_replace(array("UPF_"),array(""),$jsfun)); 
       
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile('icon/'.$id); 	  
	           $updata = $upfile->_batch_upfile('icon');		 
		 		 
		       $newfile = $updata[1]['path'];
	       
			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		              if(!is_dir($pic_dir)&&file_exists($pic_dir))
		              {
		                del_file($pic_dir);	
		              }			 
		       }
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

	    echo "<img src='{$pic_url}' id='upsrc' width='100px' height='50px'><br/><A HREF='?app=icon&act=upfile&edit=edit&picurl=$newfile&jsfun={$jsfun}&uppic={$uppic}&id={$id}'>修改图片</A>";

	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','$uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','$uppic');
				}
		     </script>";
				
	    exit;		
		
		}
     echo "
	 
<html>
<head>
<title></title>
<meta >
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<style type='text/css'>
*{
	margin: 0;
	padding: 0;
	font-size: 12px;
}
.buton {
font: 12px verdana,tahoma; 
color: #fff; 
background-color: #4a6ea5;
border:1px #003366 solid;
height:2em;
}

</style>
</head>
<body bgcolor='#ffffff' text='#000000' leftmargin='0' topmargin='0'>
				
<form name='form1' method='post' action='?app=icon&act=upfile' enctype='multipart/form-data'>

  <input id='postfile1' type='file' name='postfile1' style='height:20px;'  class='buton'>
          <select name='waterimg'>
		  <option value='0' >请选择是否加水印...</option>
          <option value='1' >加</option>
          <option value='0' >不加</option> 
          </select>
          <br/>
          缩略图大小:长(px)<input type='text' maxlength='4' size='6' value='0' name='thumb_width'> x 宽(px) <input type='text' maxlength='4' size='6'
		  . value='0' name='thumb_height'>		  
  <input  type='submit' name='Submit' value='上传文件' style='height:20px;' class='buton'>

  <input type='hidden' name='action' value='post'>
  <input type='hidden' name='jsfun' value='{$jsfun}'>    
  <input type='hidden' name='uppic' value='{$uppic}'>
  <input type='hidden' name='edit' value='{$edit}'>
  <input type='hidden' name='id' value='{$id}'>
  <input type='hidden' name='picurl' value='{$picurl}'>
</form>

</body>
</html>	 
	 
	 ";
    }





    function get_icon_str($iconarray = array())
    {

		$str ='<phpscup:icon ';
        foreach($iconarray as $key => $value)
		{
			$str .= '  '.$key."=\'".$value."\'"	;
		}
		$str .=' />';			  
        return $str;
    }		

    function config_to_str($iconarray = array())
    {

		$str =' ';
        foreach($iconarray as $key => $value)
		{
			$str .= '  '.$key."=\'".$value."\'"	;
		}
		$str .=' ';			  
        return $str;
    }

	function icon_to_array($str = '')
	{
	    if(empty($str))
		{
		 return '';
		}
		if ($this->phpscup_div == null) 
		{
			require_once (ROOT_PATH . '/lib/div.lib.php');
			$this->phpscup_div = new PhpSCup_div();

		}	

	    $this->icon_to_array = del_empty_var($this->phpscup_div->strAttribute($str));
	
		foreach($this->icon_to_array as $key=>$value)
		{
		  $this->icon_to_array[$key] = str_replace(array("\'",'\"'),array('',''),$value);

		}
	
		return 1;
	}



    function write_config($data)
    {

		 $str = '';
		 
         foreach ($data as $key => $value)
         {
               if (is_string($value) || is_numeric($value) || is_bool($value) || is_null($value))
               {
                    $str .= "define('".strtoupper($key)."','".$value."');\r\n";

                }
         }
		 		 	    	
		 write_file(ROOT_PATH . '/data/config.inc.php',"<?php\r\n".$str.'?>');

    }



  
}

?>